package br.com.commerj.dao;

import java.sql.SQLException;
import java.sql.Types;

import br.com.commerj.model.Telefone;
import br.com.commerj.model.TipoTelefone;

public class TelefoneDAO extends DAO {
	
	public String salvar(Telefone telefone) throws SQLException{
		String msg = "";
		p = null;
		c = null;
		try{
			String sql = "INSERT INTO telefone VALUES(?,?,?,?,?)";
			p = getConnection().prepareStatement(sql);
			p.setNull(1, Types.NULL);
			p.setString(2, TipoTelefone.FIXO.toString());
			p.setString(3, telefone.getDdd());			
			p.setString(4, telefone.getNumero());
			p.setInt(5, telefone.getPessoa().getCodPessoa());
			p.execute();
			c.commit();
			msg = "SALVAR";
		}catch (Exception e) {
			e.printStackTrace();
		}finally{
			try{
				if(p != null)
					p.close();
				if(c != null)
					c.close();
				}catch (SQLException e) {
					System.out.println("Erro ao fechar TelefoneDAO "+e.getMessage());
				}
		}
		return msg;
	}
	
}
